const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}
function http(url,data,callback){
  wx.request({
    url:url,
    data:data,
    header: {
      "Content-Type": "application/x-www-form-urlencoded"
    },
    method: "POST",
    dataType: "json",
    success: function(res) {
      callback(res.data)
    },
    fail: function(res) {},
    complete: function(res) {},
  })
};

//图片上传服务器
function upload_file_server(that,upload_picture_list,j){
  console.log("开始上传" +j+"图片到服务器");
  console.log(upload_picture_list);
  console.log(upload_picture_list[j]["path"])
  var upload_task=wx.uploadFile({
    url: 'http://hy.ktcx.com.cn/ttxx/uploadImg',
    filePath:upload_picture_list[j]["path"],
    name: 'file',
    header: {
      "Content-Type": "application/x-www-form-urlencoded"
    },
    formData: {'path':'wxchat'},
    success: function(res) {
      console.log(res.data);
      JSON.parse(res.data)
    },
    fail: function(res) {},
    complete: function(res) {},
  })
}
module.exports = {
  http:http,
  formatTime: formatTime,
  upload_file_server: upload_file_server
}
